﻿using System;
using System.Windows;
using System.Windows.Data;

namespace JY.Wpf.Core.Converters
{
    /// <summary>
    /// Null值转换Visibility转换器
    /// </summary>
    public class NullToVisiblityConverter : IValueConverter
    {
        /// <summary>
        /// 转换器
        /// </summary>
        /// <param name="value">Object</param>
        /// <param name="targetType">类型</param>
        /// <param name="parameter">参数</param>
        /// <param name="culture">语言</param>
        /// <returns>parameter 为0时 Null To Visible  为1时反过来</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //parameter 为0时 Null To Visible  为1时反过来
            Visibility vis = Visibility.Visible;

            if (value != null && parameter != null && parameter.ToString()=="0")
            {
                vis = Visibility.Collapsed;
            }
            else if (value == null && parameter != null && parameter.ToString() == "1")
            {
                vis = Visibility.Collapsed;
            }

            return vis;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}